package com.solution.admin.point.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.solution.admin.point.dao.PointRuleDao;
import com.solution.admin.point.entity.PointRuleEntity;
import com.solution.admin.point.service.PointRuleService;
import com.solution.common.dao.BaseDao;
import com.solution.common.service.impl.BaseServiceImpl;

/**
 * 积分规则设置信息service实现层
 * 
 * @author xu_cc
 * @date 2017-10-20 14:25:42
 */
@Service
public class PointRuleServiceImpl extends BaseServiceImpl<PointRuleEntity> implements PointRuleService {

    /**
     * 积分规则设置信息接口
     */
    @Autowired
    private PointRuleDao pointRuleDao;

    protected BaseDao<PointRuleEntity> getDao() {
        return this.pointRuleDao;
    }

    /**
     * 保存积分规则设置信息
     * 
     * @param pointRuleEntity
     *            积分规则设置信息实体
     * @return Long 添加成功积分规则设置信息的ID
     * @author xu_cc
     * @date 2017-10-20 14:25:42
     */
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public long savePointRule(PointRuleEntity pointRuleEntity) {
        // 所有规则置为无效
        pointRuleDao.updateAllDisabled(pointRuleEntity.getCreater());
        return pointRuleDao.savePointRule(pointRuleEntity);
    }

    /**
     * 获取唯一一条有效规则
     * 
     * @Title: getEnablePointRule
     * @Description:(描述)
     * @return PointRuleEntity
     * @author xu_cc
     * @throws Exception
     *             exception
     * @Date 创建时间：2017年10月24日 下午6:26:10
     */
    public PointRuleEntity getEnablePointRule() {
        return pointRuleDao.getEnablePointRule();
    }
}
